{extend name="common/base" /}
{block name='title'}编辑优惠券 - 其他管理{/block}

{block name="body"}
<article class="clearfix pd-20">
    <form action="" method="post" class="form form-horizontal" id="form-set-add">
        <input name="id" type="hidden" value="{$data.id}">
        <div class="row clearfix">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>优惠券名：</label>
            <div class="form-controls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="{$data.name}" placeholder="" id="name" name="name">
            </div>
        </div>
         <div class="row clearfix">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>优惠券状态：</label>
            <div class="form-controls col-xs-8 col-sm-9">
                <input type="radio"  value="1" {if $data.serial_number==1}checked{/if}   name="serial_number"> 可用
                <input type="radio"  value="0" {if $data.serial_number==0}checked{/if}   name="serial_number"> 不可用
            </div>
        </div>
        <div class="row clearfix">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>优惠券金额：</label>
            <div class="form-controls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="{$data.money}" placeholder="" id="money" name="money">
            </div>
        </div>
        <div class="row clearfix">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>封面图：</label>
            <div class="form-controls col-xs-8 col-sm-9">
                <img src="{$data.images}" height="100">
                <div id="uploadLists" ></div>
                <span class="btn-upload">
                        <a href="javascript:void();" class="btn btn-primary radius btn-upload"><i class="Hui-iconfont">&#xe642;</i> 浏览文件</a>
                        <input type="file"  name="btn-upload" id="btn-upload" class="input-file">
                    </span>
            </div>
        </div>


        

       
        <div class="row clearfix">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
            </div>
        </div>
    </form>

    <input name="uploadImage" type="hidden" value="{:url('upload/uploadImage')}">
    <input name="image" type="hidden" id="image" value="{$data.images}" >
</article>
{/block}

{block name="js"}
<!--请在下方写此页面业务相关的脚本-->

<script type="text/javascript" src="__LIB__/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="__LIB__/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="__LIB__/jquery.validation/1.14.0/messages_zh.js"></script>

<script type="text/javascript" src="__LIB__/webuploader/0.1.5/webuploader.min.js"></script>

<script type="text/javascript" src="__JS__/main.js"></script>

<script type="text/javascript">
    $(function(){
        /* 通过iCheck插件，美化checkbox */
        $('.skin-minimal input').iCheck({
            checkboxClass: 'icheckbox-blue',
            radioClass: 'iradio-blue',
            increaseArea: '20%'
        });
        
        /* 表单验证，提交 */
        $("#form-set-add").validate({
            rules:{
                name:{
                    required:true,
                },
                serial_number:{
                    required:true,
                },
                money:{
                    required:true,
                },
                image:{
                    required:true,
                }
                
            },
            onkeyup:false,
            focusCleanup:true,
            success:"valid",
            submitHandler:function(form){
                
                var id    = $("input[name='id']").val();
                var name = $("input[name='name']").val();
                var serial_number = $("input[type='radio']:checked").val();;
                var money = $("input[name='money']").val();
                var images = $("input[name='image']").val();
                
                $.ajax({
                    type: 'post', // 提交方式 get/post
                    url: "{:url('voucher/edit')}", // 需要提交的 url
                    data: {
                        'id': id,
                        'name': name,
                        'serial_number': serial_number,
                        'money' : money,
                        'images' : images,
                    },
                    dataType: 'json',
                    success: function(ret) { // data 保存提交后返回的数据，一般为 json 数据
                        // 此处可对 data 作相关处理
                        //console.log(ret);return false;
                        if(0 == ret.code){
                            layer.msg(ret.msg, { icon:1,time:1000 });
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.location.replace(parent.location.href)
                            parent.layer.close(index);
                        }else{
                            layer.msg(ret.msg, { icon:2,time:1000 });
                        }
                    }
                });
                
            }
        });
    });
    
    $("select[name='link_type']").bind('change',function(){
        var val = $(this).val();
        if(val == 3){
            $("input[name='link']").hide();
            $("input[name='link']").val('');
        }else{
            $("input[name='link']").show();
        }
    });
</script>
<!--/请在上方写此页面业务相关的脚本-->
{/block}
